package com.geyue.controller;

import com.geyue.common.toolbox.result.Res;
import com.geyue.core.model.IntegralFor;
import com.geyue.core.service.IntegralForService;
import com.geyue.core.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Lyon on 2017/5/16.
 */
@Controller
@RequestMapping("/for")
public class IntegralForController {

    @Autowired
    private IntegralForService integralForService;
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String list() {
        return "for/list";
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    @ResponseBody
    public Res list(Integer pageSize, Integer pageNum) {
        return Res.success("", integralForService.getPageList(pageNum, pageSize));
    }


    @RequestMapping(value = "/ok", method = RequestMethod.PUT)
    @ResponseBody
    public Res ok(Integer id) {
        return integralForService.ok(id);
    }

    @RequestMapping(value = "/no", method = RequestMethod.PUT)
    @ResponseBody
    public Res no(Integer id) {

        IntegralFor integralFor = new IntegralFor();
        integralFor.setId(id);
        integralFor.setIsOk(IntegralFor.no);

        if(integralForService.updateNotEmpty(integralFor) > 0 )
            return Res.success("审核成功!");

        return Res.fail("审核失败");
    }
}
